package com.ayf.payment.game.api.service.impl;

import com.ayf.payment.game.api.dto.GamePlayerCashRuleDTO;
import com.ayf.payment.game.api.entity.GamePlayerCashRule;
import com.ayf.payment.game.api.mapper.GamePlayerCashRuleMapper;
import com.ayf.payment.game.api.service.GamePlayerCashRuleService;
import com.swwx.charm.commons.lang.utils.BeanConvertUtils;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

@Service
public class GamePlayerCashRuleServiceImpl implements GamePlayerCashRuleService {

    @Resource
    private GamePlayerCashRuleMapper gamePlayerCashRuleMapper;

    @Override
    public GamePlayerCashRuleDTO getGamePlayerCashRuleDTOByMerchantId(Integer merchantId) {
        GamePlayerCashRule gamePlayerCashRule = new GamePlayerCashRule();
        gamePlayerCashRule.setMerchantId(merchantId);
        GamePlayerCashRule gamePlayerCashRule2 = gamePlayerCashRuleMapper.selectOne(gamePlayerCashRule);
        if (gamePlayerCashRule2 == null) {
            gamePlayerCashRule.setAlipayReplaceCharacter("#");
            gamePlayerCashRule.setDayLimitAmt("0");
            gamePlayerCashRule.setFeePrecent("0");
            gamePlayerCashRule.setLimitAmt("0");
            gamePlayerCashRule.setTimeLimitStart("0");
            gamePlayerCashRule.setTimeLimitEnd("0");
            gamePlayerCashRuleMapper.insertSelective(gamePlayerCashRule);
            gamePlayerCashRule2 = gamePlayerCashRule;
        }
        return BeanConvertUtils.convert(gamePlayerCashRule2,GamePlayerCashRuleDTO.class);
    }

    @Override
    public void saveGamePlayerCashRule(GamePlayerCashRuleDTO gamePlayerCashRuleDTO) {
        GamePlayerCashRule gamePlayerCashRule = BeanConvertUtils.convert(gamePlayerCashRuleDTO,GamePlayerCashRule.class);
        gamePlayerCashRuleMapper.updateByPrimaryKeySelective(gamePlayerCashRule);
    }
}

